package c.x.jy.service.pay.impl;

import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import c.x.jy.common.annotation.OrderLock;
import c.x.jy.common.exception.RRException;
import c.x.jy.service.lock.DistributedLock;
import c.x.jy.service.lock.Lock;
import c.x.jy.service.lock.ZLock;
import c.x.jy.service.pay.PayService;
import c.x.jy.service.redis.Cache;
import c.x.jy.service.redis.RedisConstant;
import c.x.jy.service.utils.wechat.PayCommonUtil;
import c.x.jy.service.utils.wechat.WechatConfig;
@Service
public class PayServiceImpl  implements  PayService{
   @Autowired
 private  DistributedLock distributedLock;

	@Autowired
	private Cache redisUtils;
  /**
 * @throws Exception 
   * 
   */  
//  @Lock(key="#no",leaseTime=10,isFair=true)
	@OrderLock(name="orderNo",key="openid")
@Override
public Map<String, Object> wechatPrePay(String orderNo,String no, BigDecimal receivableMoney, String comment, String requestIP, 	String openid, WechatConfig Confing)   {
 
	    if(	redisUtils.get(RedisConstant.REDISLOCK_KEY, no)!=null) {
	    	throw new RRException("请稍候再试！");
	    }
	    redisUtils.put(RedisConstant.REDISLOCK_KEY, no,1,5*60);
	    	return PayCommonUtil.wechatPrePay(no, receivableMoney, comment, requestIP, openid, Confing);
	 
		
 
 
}
  
  
}
